import React, { Component } from "react";
// NavLink有Link所有的功能，同时又具有高亮功能
import { Route, Switch, Redirect, NavLink } from "react-router-dom";

import "./08-style.css";

class Home extends Component {
  render() {
    return <div>这是home页面</div>;
  }
}
class About extends Component {
  render() {
    return <div>这是about页面</div>;
  }
}
class Detail extends Component {
  render() {
    return <div>这是detail页面</div>;
  }
}

class App extends Component {
  state = {};
  render() {
    return (
      <>
        <h2>导航高亮</h2>
        <ul>
          {/* NavLink有activeClassName属性，用来修改active类名 */}
          <li>
            <NavLink to="/home" activeClassName="select">
              首页
            </NavLink>
          </li>
          <li>
            <NavLink to="/about" activeClassName="select">
              关于页
            </NavLink>
          </li>
          <li>
            <NavLink to="/detail" activeClassName="select">
              详情页
            </NavLink>
          </li>
        </ul>

        <hr />

        <Switch>
          <Redirect from="/" to="/home" exact></Redirect>
          <Route path="/home" component={Home}></Route>
          <Route path="/about" component={About}></Route>
          <Route path="/detail" component={Detail}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
